package cn.com.victorysoft.ylgl.service.fracturingpressure.service.jobTest.impl;

import cn.com.victorysoft.ylgl.service.commons.mybatis.MybatisRepository;
import cn.com.victorysoft.ylgl.service.commons.mybatis.paging.bean.DataPaging;
import cn.com.victorysoft.ylgl.service.commons.mybatis.paging.bean.PageRequest;
import cn.com.victorysoft.ylgl.service.commons.mybatis.paging.bean.Pageable;
import cn.com.victorysoft.ylgl.service.commons.util.IDUtils;
import cn.com.victorysoft.ylgl.service.fracturingpressure.domain.jobTest.StratifiedFracturProfile;
import cn.com.victorysoft.ylgl.service.fracturingpressure.domain.jobTest.StratifiedFracturProfileVO;
import cn.com.victorysoft.ylgl.service.fracturingpressure.service.jobTest.IStratifiedFracturProfileService;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.Map;

/**
 * 分层压裂剖面
 * Created by Administrator on 18/3/16.
 */
@org.springframework.stereotype.Component
public class StratifiedFracturProfileService implements IStratifiedFracturProfileService {
    private static final Logger logger = LoggerFactory.getLogger(StratifiedFracturProfileService.class);
    @Resource
    private MybatisRepository mybatisRepository;
    @Override
    public StratifiedFracturProfile getById(String dataId) {
        Map<String, Object> params = new HashMap<>();
        params.put("dataId", dataId);
        return this.mybatisRepository.selectOne(
                "cn.com.victorysoft.ylgl.webapp.service.jobTest.StratifiedFracturProfileMapper.selectByPrimaryKey",
                params);
    }

    @Override
    public StratifiedFracturProfileVO getDtoBy(String dataId) {
        Map<String, Object> params = new HashMap<>();
        params.put("dataId", dataId);
        return this.mybatisRepository.selectOne(
                "cn.com.victorysoft.ylgl.webapp.service.jobTest.StratifiedFracturProfileMapper.selectDtoByPrimaryKey",
                params);
    }

    @Override
    public DataPaging<StratifiedFracturProfileVO> queryPagingList(String yt, String qk, String dk, String cw, String jh, String startDate, String endDate, String rows, String page) {
        Map<String, Object> params = new HashMap<>();
        params.put("yt", yt);
        params.put("qk", qk);
        params.put("dk", dk);
        params.put("cw", cw);
        params.put("jh", jh);
        params.put("startDate", startDate);
        params.put("endDate", endDate);
        int _page = 1;
        int _rows = Integer.MAX_VALUE;
        if (StringUtils.isNotBlank(page) && StringUtils.isNotBlank(rows)) {
            _page = Integer.parseInt(page);
            _rows = Integer.parseInt(rows);
        }

        PageRequest pageRequest = new PageRequest(_page, _rows, params  );
        DataPaging<StratifiedFracturProfileVO> dataPaging = this.mybatisRepository.selectPaging(
                "cn.com.victorysoft.ylgl.webapp.service.jobTest.StratifiedFracturProfileMapper.selectPagingVO",
                (Pageable) pageRequest);
        return dataPaging;
    }


    @Override
    public int insert(StratifiedFracturProfile record) {
        record.setDataId(IDUtils.getUUID32());
        this.mybatisRepository.insert("cn.com.victorysoft.ylgl.webapp.service.jobTest.StratifiedFracturProfileMapper.insert",record);
        return 1;
    }

    /**
     * @param dataids id以;隔开，比如：1;2;
     * @return 返回影响的行数
     */
    @Override
    public int deleteByKeys(String dataids) {
        Map<String, Object> params = new HashMap<>();
        params.put("dataIds", dataids);
        this.mybatisRepository.delete(
                "cn.com.victorysoft.ylgl.webapp.service.jobTest.StratifiedFracturProfileMapper.deleteByKeys",params);
        return 1;
    }

    @Override
    public int deleteByPrimaryKey(String dataId) {
        Map<String, Object> params = new HashMap<>();
        params.put("dataId", dataId);
        this.mybatisRepository.delete(
                "cn.com.victorysoft.ylgl.webapp.service.jobTest.StratifiedFracturProfileMapper.deleteByPrimaryKey",params);
        return 1;
    }

    @Override
    public int updateByPrimaryKey(StratifiedFracturProfile record) {
        this.mybatisRepository.update("cn.com.victorysoft.ylgl.webapp.service.jobTest.StratifiedFracturProfileMapper.updateByPrimaryKey",record);
        return 1;
    }
}
